<?php
	class Default_Model_DbTable_Role extends Zend_Db_Table_Abstract
	{
	    protected $_name = 'acl_roles';
	    protected $_sequence = '_seq_acl_roles';

	    protected $_primary = 'id';
	    protected $_pk = 'id';


	    public function getRole($id, $returnArray = false)
	    {
	        $id = (int)$id;
	    	$row = $this->fetchRow($this->_pk .'= '. $id);
	        if (!$row) {
	            throw new Exception("Count not find row $id");
	        }
	        if ($returnArray == true) {
		        return $row->toArray();
	        }
	        return $row;

	    }

	    public function addRole($data)
	    {

	        $this->insert($data);
	        $id = $this->_db->lastInsertId($this->_name);
	        return $id;
	    }

	    public function updateRole($id, $data)
	    {
	        $this->update($data, $this->_pk . ' = ' . (int)$id);

	    }

	    public function deleteRole($id)
	    {
	        $this->delete($this->_pk .'=' . (int)$id);
	    }

	    public function getRolesAsPairs()
	    {
	    	$rows = $this->_db->fetchPairs( $this->select()->from($this->_name, array('name', 'label')) );
	    	//$rows = $this->fetchAll();
	        if (!$rows) {
	            throw new Exception("Count not find rows");
	        }
	        return $rows;

	    }
	}